// Copyright (c) 2011 Vratislav Cermak (vratacermak@gmail.com)
//  
// This file is part of SrtSync Project. See http://code.google.com/p/srtsync/ for more information.
//  
// SrtSync is an open source project. Using of SrtSync is free of charge.
// It is distributed under GNU General Public License version 3 (GPLv3).
// GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
//  
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.

using System;
using System.Text;
using SrtSync.Core;

namespace SrtSync.GtkWidgets
{
	public class EntryNode : Gtk.TreeNode
	{
		private string _cachedTexts;
			
		public EntryNode(Entry entry)
		{
			Entry = entry;
		}
		
		public Entry Entry { get; private set; }
			
		[Gtk.TreeNodeValue(Column = 0)]
		public int Index
		{
			get
			{
				return Entry.Index;
			}
		}
			
		[Gtk.TreeNodeValue(Column = 1)]
		public string Texts
		{
			get
			{
				if (String.IsNullOrEmpty(_cachedTexts))
				{
					StringBuilder builder = new StringBuilder();
					foreach (string text in Entry.Texts)
					{
						builder.AppendLine(text);
					}
					_cachedTexts = builder.ToString().Trim();
				}
				return _cachedTexts;
			}
		}
		
		public void Refresh()
		{
			_cachedTexts = null;
		}
	}
}